home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1995 November
/
EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso
/
earcd
/
util
/
misc
/
unt.lha
/
UnT.e
< prev
Wrap
Text File
|
1994-03-28
|
5KB
|
197 lines
/* This program should take a .t64 file and pull it apart into */
/* the original, separate CBM files. */
/* Written by pbhoeffl@undergrad.math.uwaterloo.ca */
/* on March 26-7, 1994 */
/* Development Suite: */
/* Hardware: A500 KS1.3 WB1.3 */
/* Software: Amiga E v2.1b, Vim 2.0 */
/* I maintain no copyright on this program, and hereby release */
/* it into the public domain. If I am violating someone elses */
/* copyright by releasing this as such... well, I guess that's */
/* my tough luck. */
ENUM NOARG, NOARCHIVE, EMPTYARCHIVE, NOMEMORY, READERROR
ENUM CANTCREATE, WRITEERROR
DEF flen, handle=NIL, mem
PROC main () HANDLE
DEF i, j, numFiles, numUsed, prompt[16]:STRING
IF arg[0]=0 THEN Raise (NOARG)
/* WriteF ('Archive is: \s\n', arg) */
handle := Open(arg, OLDFILE)
IF handle = NIL THEN Raise (NOARCHIVE)
flen := FileLength (arg)
IF flen < 1 THEN Raise (EMPTYARCHIVE)
/* WriteF ('Located \s. Size=\d\n', arg, flen) */
mem := New (flen)
IF mem = NIL THEN Raise (NOMEMORY)
/* WriteF ('Memory successfully allocated.\n') */
IF Read (handle, mem, flen) <> flen THEN Raise (READERROR)
/* WriteF ('Read archive successfully.\n', arg) */
/* We're done with the archive file */
Close (handle); handle := NIL
WriteF ('User Description : ')
print_text (40, 24); WriteF ('\n')
/*
WriteF ('DOS Description :\n')
print_text (0, 32); WriteF ('\n')
*/
numFiles := make_int16 (34)
WriteF ('Number of Entries: \d\n', numFiles)
numUsed := make_int16 (36)
WriteF ('Number Used : \d\n', numUsed)
WriteF ('\nScanning Tape-Archive...\n')
FOR i := 0 TO numFiles-1
IF mem[64+(i*32)] = 1
WriteF ('#\d ', i)
print_entry (64+(i*32))
ENDIF
ENDFOR
WriteF ('Done\n\n')
IF numUsed = 0
WriteF ('According to the header info, there are no files in this archive.\n')
WriteF ('This is probably bogus. The first entry is likely the converted file.\n\n')
print_entry (64)
WriteF ('Do you wish to extract this file (Y/N)? ')
ReadStr (stdout, prompt); UpperStr (prompt)
IF prompt[0] = "Y"
WriteF ('Type the name you wish to give to this file:\n')
ReadStr (stdout, prompt)
IF StrLen (prompt) > 0
extract_file (64, prompt)
ENDIF
ENDIF
ELSE
FOR i := 0 TO numFiles-1
IF mem[64+(i*32)] = 1
/* Pull & trim the filename from the directory entry */
j := 16
WHILE (mem[(64+(i*32)) + 16 + j - 1] = " ") AND (j >= 0)
j := j-1
ENDWHILE
SetStr (prompt, j)
StrCopy (prompt, mem + (64+(i*32)) + 16, j)
extract_file (64+(i*32), prompt)
ENDIF
ENDFOR
ENDIF
CleanUp(0)
/* Error conditions */
EXCEPT
SELECT exception
CASE NOARG
WriteF ('Usage: UnT <archive.t64>\n')
CASE NOARCHIVE
WriteF ('Unable to open \s!\n', arg)
CASE EMPTYARCHIVE
WriteF ('Archive \s is EMPTY!\n', arg)
CASE NOMEMORY
WriteF ('Could not allocate enough memory.\n')
CASE READERROR
WriteF ('Read Error on \s.\n', arg)
DEFAULT
WriteF ('BAD SCENE, MAN!!!\n')
ENDSELECT
Close (handle)
CleanUp (-1)
ENDPROC
PROC print_text (start, length)
DEF s[80]:STRING
SetStr (s, length)
StrCopy (s, mem+start, length)
WriteF ('\e[40;33m\s\e[40;31m', s)
ENDPROC
PROC print_entry (rec_base)
DEF fileType
fileType := mem[rec_base + 1]
SELECT fileType
CASE 1
WriteF ('PRG "')
CASE 68
WriteF ('PRG "')
/* other CASEs would be implemented if I had my 1541 manual here */
DEFAULT
WriteF ('??? "')
ENDSELECT
print_text (rec_base + 16, 16)
WriteF ('" Start=$\z\h[4] ', make_int16 (rec_base + 2))
WriteF ('End=$\z\h[4]\n', make_int16 (rec_base + 4))
ENDPROC
PROC extract_file (rec_base, name) HANDLE
DEF length, i
WriteF ('Extracting "\s"...', name)
length := make_int16(rec_base + 4) - make_int16(rec_base + 2)
handle := Open (name, NEWFILE)
IF handle = NIL THEN Raise (CANTCREATE)
i := Write (handle, (mem + rec_base + 2), 2)
IF i <> 2 THEN Raise (WRITEERROR)
i := Write (handle, (mem + make_int16 (rec_base + 8)), length)
IF i <> length THEN Raise (WRITEERROR)
Close (handle)
WriteF (' OK\n')
EXCEPT
SELECT exception
CASE CANTCREATE
WriteF ('Unable to create file!\n')
CASE WRITEERROR
WriteF ('Write Error!\n')
DEFAULT
WriteF ('BAD SCENE, MAN!!!\n')
ENDSELECT
Close (handle)
CleanUp (-1)
ENDPROC
PROC make_int16 (address)
RETURN ( mem[address] + (256 * mem[address+1]) )
ENDPROC